import Vue from 'vue'
import Vuex from 'vuex'
import { getRealList, getHotList, getBrokerList, getResoldList } from '@/api'
import router from '../router'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    realList: [], //楼市资讯
    hotList: [], //热门楼盘
    brokerList: [], //经纪人
    resoldList: [], //二手房
    city: '请选择'
  },
  mutations: {
    //获取楼市资讯数据
    GET_REAL_LIST(state, data) {
      state.realList = data
    },
    //获取热门楼盘数据
    GET_HOT_LIST(state, data) {
      state.hotList = data
    },
    //获取经纪人数据
    GET_BROKER_LIST(state, data) {
      state.brokerList = data
    },
    //获取二手房数据
    GET_RESOLD_LIST(state, data) {
      state.resoldList = data
    },
    GET_LIST(state, data) {
      state.city = data;
      router.push('/homePage')
    }
  },
  actions: {
    //获取楼市资讯数据
    async getRealList({ commit }) {
      const res = await getRealList()
      // if (res.data.code === 0) {
      // } else {
      // router.push('/login')
      // }
      commit('GET_REAL_LIST', res.data.data)
      console.log(res);
    },
    //获取热门楼盘数据
    async getHotList({ commit }) {
      const res = await getHotList()
      console.log(res);
      commit('GET_HOT_LIST', res.data.data)
    },
    //获取经纪人数据
    async getBrokerList({ commit }) {
      const res = await getBrokerList()
      console.log(res);
      commit('GET_BROKER_LIST', res.data.data)
    },
    //获取二手房数据
    async getResoldList({ commit }) {
      const res = await getResoldList()
      console.log(res);
      commit('GET_RESOLD_LIST', res.data.data)
    },
  },
  modules: {
  }
})
